home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 11
/
Mac Magazin and MacEasy Magazine CD - Issue 11.iso
/
Sharewarebibliothek
/
Entwickler
/
CDEF-DeBugger 2.0 ƒ
/
Error.c
< prev
next >
Wrap
Text File
|
1995-05-31
|
3KB
|
93 lines
// this file needs "errorIcon.r" to work
// use this to report an error to the user. Better used for debugging, but it could be modified
// any way you see fit. Uses the icon provided in "errorIcon.r"
// prototypes
void ReportError( Str255 errorMsg );
Boolean CompareStr( Str255 srcA, Str255 srcB );
// globals
extern Main myMain;
/******************************************************************************
A simple procedure for reporting errors.
*******************************************************************************/
void ReportError( Str255 errorMsg )
{
short maxStrSize, iconID, winHorz, winVert, strWidth;
Rect theRect;
GrafPtr thePort;
Point localPt;
// store the current port and set up some intial variables
GetPort( &thePort );
// make sure the error string isn't to large.
if( errorMsg[0] > 128 ) {
errorMsg[0] = 128;
}
// grab our icon dude.
myMain.icon = GetCIcon( 32000 );
HLock( (Handle)myMain.icon );
// position the window in global coordinates to center on the main screen.
SetRect( &theRect, 0, 0, 400, 200 );
myMain.error = NewCWindow( nil, &theRect, "\p", FALSE, dBoxProc, (WindowPtr)-1, false, ERROR_WINDOW );
SetPort( myMain.error );
// set the text stuff up
TextFont( 9 );
TextSize( 9 );
TextFace( 0 );
strWidth = StringWidth( errorMsg );
// add the size of our icon and the space between it and our text and space along the
// window frame. we will use this to size our window.
strWidth += 32 + 14 + 28;
// make sure that it's not to small. just in case.
if( strWidth < 100 ) {
strWidth = 100;
}
// no let's resize our window to fit the size.
winHorz = ( qd.screenBits.bounds.right - qd.screenBits.bounds.left ) / 2;
winVert = ( qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ) / 3;
SizeWindow( myMain.error, strWidth, 60, TRUE );
MoveWindow( myMain.error, winHorz - (strWidth / 2), winVert, TRUE );
ShowWindow( myMain.error );
// draw our nifty icon dude.
SetRect( &theRect, (*myMain.error).portRect.left + 14, (*myMain.error).portRect.top + 14,
(*myMain.error).portRect.left + 46, (*myMain.error).portRect.top + 46 );
PlotCIcon( &theRect, myMain.icon );
// draw the error message.
MoveTo( 60, 25 );
TextFace( 1 );
DrawString( "\pError Report:" );
TextFace( 0 );
MoveTo( 60, 40 );
DrawString( errorMsg );
// store the message for later retrieval
BlockMove( &errorMsg[0], &myMain.errMsg[0], errorMsg[0] );
// do a system beep just for the excitement of things.
SysBeep( 1 );
// just create a little loop untill the user presses the mouse button
do {
} while ( !Button());
// Handle anything we might of done.
HUnlock( (Handle)myMain.icon );
DisposCIcon( myMain.icon );
DisposeWindow( myMain.error );
ExitToShell();
}